package com.siteseat.common.json;

import java.io.IOException;
import java.util.Date;

import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializerProvider;

import com.siteseat.common.misc.TimeHelper;

public class DateSerializer extends JsonSerializer<Date> {

  /**
   * {@inheritDoc}
   */
  @Override
  public void serialize( Date value, JsonGenerator jgen, SerializerProvider provider ) throws IOException,
          JsonProcessingException {
    jgen.writeString( TimeHelper.format( value ) );
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public Class<Date> handledType() {
    return Date.class;
  }

}
